package com.bop.dehong.decaifu.fragment;

import android.text.Html;
import android.view.View;
import android.widget.AdapterView;
import android.widget.TextView;

import com.base.dehong.http.RequestCallBack;
import com.bop.dehong.R;
import com.bop.dehong.base.BaseFragment;
import com.bop.dehong.config.Config;
import com.bop.dehong.info.entity.ProductItemEntity;
import com.bop.dehong.info.entity.ToubiaoProductInfoEntity;
import com.bop.dehong.http.model.ToubiaoProductInfoModel;

public class ProductIntroduct extends BaseFragment {
	private TextView loan_info, loan_use, pay_source;
	private String id;
	private ToubiaoProductInfoModel toubiaoProductInfoModel;
	private ProductItemEntity entity;

	@Override
	protected void initTop() {
		mPageName = getClass().getName();
	}

	@Override
	protected void initUI() {
		loan_info = getView(R.id.loan_info);
		loan_use = getView(R.id.loan_use);
		pay_source = getView(R.id.pay_source);
		id = getActivity().getIntent().getExtras().getString(Config.CAT_ID);
	}

	@Override
	public void initData() {
		if (entity != null) {
			CharSequence charSequence1 = Html.fromHtml(entity.getContent());  
			loan_info.setText(charSequence1);
			CharSequence charSequence2 = Html.fromHtml(entity.getLoan_purpose());  
			loan_use.setText(charSequence2);
			CharSequence charSequence3 = Html.fromHtml(entity.getRepay_source());  
			pay_source.setText(charSequence3);
		}else {
			showProgressDialog();
			if (toubiaoProductInfoModel == null) {
				toubiaoProductInfoModel = new ToubiaoProductInfoModel(getActivity(), callback);
			}
			toubiaoProductInfoModel.doNet(id);
		}
	}

	RequestCallBack<ToubiaoProductInfoEntity> callback = new RequestCallBack<ToubiaoProductInfoEntity>() {

		@Override
		public void end() {
			disappearProgressDialog();
		}
		
		public void onSuccess(ToubiaoProductInfoEntity info) {
			entity = info.getItem();
			CharSequence charSequence1 = Html.fromHtml(entity.getContent());  
			loan_info.setText(charSequence1);
			CharSequence charSequence2 = Html.fromHtml(entity.getLoan_purpose());  
			loan_use.setText(charSequence2);
			CharSequence charSequence3 = Html.fromHtml(entity.getRepay_source());  
			pay_source.setText(charSequence3);
			super.onSuccess(info);
		};
		
	};
	
	@Override
	protected int getContentViewId() {
		return R.layout.fragment_productinfo;
	}

	@Override
	public void onClick(View v)
	{
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position,
			long id)
	{
		// TODO Auto-generated method stub
		
	}

}
